const JWT = require("jsonwebtoken");
const secret = "xiaoming_token";

const obj = {
  encode(value, expire = "1h") {
    return JWT.sign(value, secret, { expiresIn: expire });
  },
  decode(token) {
    try {
      return JWT.verify(token, secret);
    } catch (err) {
      return false;
    }
  },
};

module.exports = obj;
